/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.manage.core.service.facade.RoleServiceFacade;
import info.peigen.hotpot.manage.core.service.order.RoleCreateOrder;
import info.peigen.hotpot.manage.core.service.order.RoleEditOrder;
import info.peigen.hotpot.manage.core.service.result.RoleCreateResult;
import info.peigen.hotpot.manage.core.service.result.RoleEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(RoleService)</b>
 * "角色" 服务实现
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings({"unused", "rawtypes"})
@Component
public class RoleService extends AbstractHotpotManageService implements RoleServiceFacade {

    @Override
    public RoleCreateResult create(RoleCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new RoleCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(roleCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(roleStoreProcessor, roleCreateResultProcessor);
            }
        });
        return (RoleCreateResult) serviceContext.getResult();
    }

    @Override
    public RoleEditResult edit(RoleEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new RoleEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(roleActiveProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(roleEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(roleStoreProcessor, roleEditResultProcessor);
            }
        });
        return (RoleEditResult) serviceContext.getResult();
    }
}